{% load i18n %}
<div class="btn-group export">

  <a class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown" href="#">
    <i class="icon-share"></i> 导入 <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
      <li><a data-toggle="modal" data-target="#export-modal-import-excel"><i class="icon-circle-arrow-down"></i> 导入 Excel</a></li>
  </ul>
    <script>
        function fileChange(target){
//检测上传文件的类型
//             //获取绝对路径
//             alert(target.value);
//             files=target.files
//              for (var i = 0; i < files.length; i++) {
//
//                alert("files"+ files[i]);
//                alert("paths"+ files[i]['webkitRelativePath']);
//
//             }
//         //获取绝对路径
            var imgName = document.all.submit_upload.value;
            var ext,idx;
            if (imgName == ''){
                document.all.submit_upload_b.disabled=true;
                alert("请选择需要上传的 xls 文件!");
                return;
            } else {
                idx = imgName.lastIndexOf(".");
                if (idx != -1){
                    ext = imgName.substr(idx+1).toUpperCase();
                    ext = ext.toLowerCase( );
                    if (ext != 'xls' && ext != 'xlsx'){
                        document.all.submit_upload_b.disabled=true;
                        alert("只能上传 .xls 类型的文件!");
                        return;
                    }
                } else {
                    document.all.submit_upload_b.disabled=true;
                    alert("只能上传 .xls 类型的文件!");
                    return;
                }
            }
        }
    </script>
    <div id="export-modal-import-excel" class="modal fade">
      <div class="modal-dialog">
        <div class="modal-content">
          <form method="post" action="" enctype="multipart/form-data">
              {% csrf_token %}
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">导入 Excel</h4>

          </div>
          <div class="modal-body">

            <input type="month" name="month" id="month" />
              <div  id="date">


                  <label>风场</label>

                            <select name="fengc">
                              <option value="1" data-selectable="" class="option">大山台风电场</option>
                                <option value="2" data-selectable="" class="option">蒋家坪风电场</option>
                                <option value="3" data-selectable="" class="option">卧龙洞风电场</option>
                                <option value="4" data-selectable="" class="option">牛心堡风电场</option>
                                <option value="5" data-selectable="" class="option">鹰鹞山风电场</option>
                                <option value="6" data-selectable="" class="option">瑶台山风电场</option>
                                <option value="7" data-selectable="" class="option">冷口风电场1</option>
                                <option value="8" data-selectable="" class="option">云盖寺风电场</option>
                                <option value="9" data-selectable="" class="option">尚家坪风电场</option>
                                <option value="10" data-selectable="" class="option">米嘉峪风电场</option>
                            </select>
                  <br>
                  <label>采集时间</label><input type="date" name="date" />
              </div>

            <input type="file" onchange="fileChange(this)" name="excel" id="submit_upload">
            <div id="moban">
                <!--<a>下载模板{{request}}</a>-->
              <br>
              <button class="btn" onclick="getmb();return false;"><i class="fa fa-share"></i> {% trans "下载模板" %}</button>
            </div>

          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
            <button class="btn btn-success" type="submit" id="submit_upload_b"><i class="icon-share"></i> 导入</button>
          </div>
          </form>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dalog -->
    </div><!-- /.modal -->

</div>

<script>
    aa = '{{request}}'
        // alert(aa.indexOf('yxdata'))
        // filename=''
        if(aa.indexOf('yspdata')>-1){
            // alert('aa',aa)
            $('#date').show();
            $('#month').hide();
            $('a[href="/app/yspdata/add/"]').parent().hide()
        }else{

            $('#date').hide();
            $('#month').show();
        }

    function getmb() {
        aa = '{{request}}'
        // alert(aa.indexOf('yxdata'))
        filename=''
        if(aa.indexOf('yxdata')>-1){
            filename='影响电量情况分析上报模板.xlsx'
        }else if(aa.indexOf('wgdata')>-1){
            filename='oms无功非正常投退上报模板.xlsx'
        }else if(aa.indexOf('ydyglyxssdata')>-1){
            filename='月度预估利用小时数上报模板.xlsx'
        }else if(aa.indexOf('jdbhsxzdata')>-1){
            filename='继电保护双细则月报上报模板.xlsx'
        }else if(aa.indexOf('zdhzjhdata')>-1){
            filename='自动化周计划上报模板.xlsx'
        }else if(aa.indexOf('zdhrqjhdata')>-1){
            filename='自动化日前计划上报模板.xlsx'
        }else if(aa.indexOf('rqtdjhdata')>-1){
            filename='日前停电计划上报模板.xlsx'
        }else if(aa.indexOf('ddydjhdata')>-1){
            filename='调度月度计划上报模板v0.xlsx'
        }else if(aa.indexOf('yspdata')>-1){
            filename='油色谱分析导入模板.xlsx'
        }else if(aa.indexOf('devdata')>-1){
            filename='发策部导入数据模板.xlsx'
        }


        // yspdata
        if(filename!=''){
            var link = document.createElement('a');
            link.setAttribute("download", "");
            link.href = "http://dl.guofeifei.com:8084/download/?subpath=moban&filename="+filename;
            link.click();
        }else{
            alert('未配置模板，请联系管理员配置');
        }
    }
</script>